home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / mildred / lha / remap.lha / Merge.ascii next >
Text File  |  1999-01-20  |  9KB  |  272 lines

  1. WBStartup
  2.  
  3.  
  4. DEFTYPE.w
  5. MCPU Processor
  6. Mc2pCPUmode Processor
  7.  
  8. *ScrVP._ViewPort=0
  9. IsAGA.b=False
  10. Dim PlanarBuf.l(2) ; Base address of planar memory to output c2p to (allowed up to triple buffers)
  11.  
  12. PrefDisplayID.l=$0 ; Default ModeID
  13. PrefDisplayWidth.w=320 ; Default Width
  14. PrefDisplayHeight.w=240 ; Default Height
  15. PrefDisplayBuffering.b=1 ; 1..3. 1=Singlebuffered, 2=Doublebuffered, 3=Triplebuffered
  16.  
  17. SMRMinX=320 ; Minimum width
  18. SMRMinY=240 ; Minimum height
  19. SMRMaxX=640 ; Maximum width
  20. SMRMaxY=480 ; Maximum height
  21.  
  22. ;Either include SMR.bb2, or set PrefDisplayID, Width and Height to valid numbers (read from a prefs file?)
  23. INCLUDE "SMR.bb2"
  24.  
  25. Function.b InitDisplay{Title$}
  26. ;Creates a display for AGA or Graphics-Card output
  27. ;Title$=The screen title (not displayed)
  28.   SHARED PrefDisplayWidth.w,PrefDisplayHeight.w,PrefDisplayBuffering.b
  29.   SHARED *ScrVP._ViewPort,PrefDisplayID.l,IsAGA.b,PlanarBuf()
  30.   ;Open a test screen first to a) test for AGA or GFX-Card, and b) because the dimensions might be
  31.   ;too large to open a chipram screen, and the dimensions for AGA have not yet been reduced to within limits
  32.   Dim ScrTags.TagItem(13)
  33.   Rect.Rectangle\MinX=0,0,320,240 ; For test
  34.   ScrTags(0)\ti_Tag=#SA_Width,320 ; For test
  35.   ScrTags(1)\ti_Tag=#SA_Height,240; For test
  36.   ScrTags(2)\ti_Tag=#SA_Depth,8
  37.   ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
  38.   ScrTags(4)\ti_Tag=#SA_Type,$F
  39.   ScrTags(5)\ti_Tag=#SA_Quiet,True
  40.   ScrTags(6)\ti_Tag=#SA_ShowTitle,False
  41.   ScrTags(7)\ti_Tag=#SA_Behind,True
  42.   ScrTags(8)\ti_Tag=#SA_DClip,&Rect ; For test
  43.   ScrTags(9)\ti_Tag=#SA_Exclusive,False
  44.   ScrTags(10)\ti_Tag=#SA_Draggable,True
  45.   ScrTags(11)\ti_Tag=#SA_AutoScroll,False
  46.   ScrTags(12)\ti_Tag=#TAG_DONE,0
  47.   ScrTags(13)\ti_Tag=#TAG_DONE,0
  48.   UsedChip.l=((320 LSR 3)*240)*8 ; With test params (depth 8)
  49.   FreeChip.l=AvailMem_(#MEMF_CHIP)
  50.   Forbid_
  51.   If ScreenTags(0,Title$,&ScrTags(0))<>0 ; Test for GFX-Card or AGA
  52.     NowChip.l=AvailMem_(#MEMF_CHIP)
  53.     Permit_
  54.     If FreeChip-NowChip<UsedChip
  55.       ; Graphics card screen
  56.       IsAGA=False
  57.       PrefDisplayWidth AND $FFF0 ; For gfx-cards, width to nearest 16
  58.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  59.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  60.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight*PrefDisplayBuffering
  61.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  62.       VWait 5 ; seems to be necessary (safer)
  63.       Free Screen 0
  64.       VWait 5
  65.       If ScreenTags(0,Title$,&ScrTags(0))<>0
  66.         For Loop.w=0 To PrefDisplayBuffering-1
  67.           If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  68. If Window(Loop,0,PrefDisplayHeight*Loop,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
  69.           Menus Off
  70.           ScreensBitMap 0,Loop
  71.           *TmpBmp.bitmap=Addr BitMap(Loop)
  72.           Offset.l=*TmpBmp\_ebwidth*(PrefDisplayHeight*Loop)
  73.           For DLoop.w=0 To 8-1 ; Depth of 8
  74.             *TmpBmp\_data[DLoop]=*TmpBmp\_data[DLoop]+Offset
  75.           Next DLoop
  76.         Next Loop
  77.       Else
  78.         Function Return False
  79.       EndIf
  80.     Else
  81.       ; AGA screen
  82.       IsAGA=True
  83.       PrefDisplayWidth AND $FFC0 ; For AGA, width to nearest 64
  84.       ScrTags(0)\ti_Tag=#SA_Width,PrefDisplayWidth
  85.       Rect.Rectangle\MinX=0,0,PrefDisplayWidth,PrefDisplayHeight
  86.       ScrTags(1)\ti_Tag=#SA_Height,PrefDisplayHeight ; Seperate buffers
  87.       ScrTags(8)\ti_Tag=#SA_DClip,&Rect
  88.       ScrTags(3)\ti_Tag=#SA_DisplayID,PrefDisplayID
  89.       Forbid_
  90.       VWait 5 ; seems to be necessary (safer)
  91.       Free Screen 0
  92.       VWait 5
  93.       For Loop.w=0 To PrefDisplayBuffering-1
  94.         If Loop=0 Then WFlags.l=$1900 Else WFlags.l=$800
  95.         If AvailMem_(#MEMF_CHIP)>=(PrefDisplayWidth*PrefDisplayHeight)+16
  96.           Memory.l=AllocMem((PrefDisplayWidth*PrefDisplayHeight)+16,$10002) ; Chip bitmap
  97.           Memory=(Memory+16) AND $FFFFFFF0 ; Align for move16's
  98.           If Memory<>0
  99.             CludgeBitMap Loop,PrefDisplayWidth,PrefDisplayHeight,8,Memory ; Depth 8
  100.             If Loop=0
  101.               ScrTags(12)\ti_Tag=#SA_BitMap,Addr BitMap(0)
  102.               If ScreenTags(0,Title$,&ScrTags(0))=0
  103.                 Permit_
  104.                 Function Return False
  105.               EndIf
  106.             EndIf
  107. If Window(Loop,0,0,PrefDisplayWidth,PrefDisplayHeight,WFlags,"",0,0)=0 Then Function Return False
  108.             Menus Off
  109.           Else
  110.             Permit_
  111.             Function Return False
  112.           EndIf
  113.         Else
  114.           Permit_
  115.           Function Return False
  116.         EndIf
  117.         PlanarBuf(Loop)=Memory
  118.       Next Loop
  119.       Permit_
  120.     EndIf
  121.     DEFTYPE.DimensionInfo DimInfoBuf
  122.     GetDisplayInfoData_ FindDisplayInfo_(PrefDisplayID) AND $FFFFFFFF,&DimInfoBuf,SizeOf.DimensionInfo,#DTAG_DIMS,0
  123.     PrefDisplayLeft.w=((DimInfoBuf\TxtOScan\MaxX)-PrefDisplayWidth)/2
  124.     PrefDisplayTop.w=((DimInfoBuf\TxtOScan\MaxY)-PrefDisplayHeight)/2
  125.     *Scr._Screen=Peek.l(Addr Screen(0))
  126.     *ScrVP=ViewPort(0)
  127.     *ScrVP\DxOffset=PrefDisplayLeft,PrefDisplayTop
  128.     ScrollVPort_ *ScrVP
  129.     RethinkDisplay_
  130.     Menus Off
  131.     If *ScrVP\DHeight<>PrefDisplayHeight
  132.       Forbid_
  133.       *Scr\Height=PrefDisplayHeight ; Enforce y clipping
  134.       Permit_
  135.     EndIf
  136.     ScreenToFront_ *Scr
  137.     Function Return True
  138.   Else
  139.     Permit_
  140.     Function Return False
  141.   EndIf
  142. End Function
  143.  
  144. .Main
  145. #ObjSize=160
  146. InitPalette 0,256
  147. If InitDisplay{"Game"}=False Then Goto Finish
  148. InitBank 0,PrefDisplayWidth*PrefDisplayHeight,$10000
  149. CludgeBitMap 4,PrefDisplayWidth,PrefDisplayHeight,8,Bank(0)
  150. LoadBitMap 4,"Orion.IFF",0
  151. ShowPalette 0
  152. *RP._RastPort=RastPort(0)
  153. Mc2pWindow 0,PrefDisplayWidth,PrefDisplayHeight ; Need this line in some form or other
  154. MCludgeBitmap 4,PrefDisplayWidth,PrefDisplayHeight*PrefDisplayBuffering,*RP\_BitMap\Planes-16
  155. MBitmap 0,PrefDisplayWidth,PrefDisplayHeight+#ObjSize
  156. MPlanar16ToBitmap 0,Bank(0),PrefDisplayWidth,PrefDisplayHeight,PrefDisplayWidth,PrefDisplayHeight
  157. MBitmap 1,PrefDisplayWidth,PrefDisplayHeight+#ObjSize
  158. MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,0,0
  159. MUseBitmap 0
  160. MGetaShape 0,128,60,#ObjSize,#ObjSize
  161. MQueue 0,1
  162.  
  163. .Table
  164. VWait 5
  165. MTable 0,256*256
  166. ;*** precalculated ***
  167. If ReadFile(0,"Orion.Table")=0 Then Goto Finish
  168. ReadMem 0,MTablePtr,256*256
  169. CloseFile 0
  170. ;*** precalculated ***
  171. ;*** runtime ***
  172. ;Dim R(256),G(256),B(256)
  173. ;PaletteInfo 0
  174. ;For c=0 To 255
  175. ;  R(c)=AGAPalRed(c)
  176. ;  G(c)=AGAPalGreen(c)
  177. ;  B(c)=AGAPalBlue(c)
  178. ;Next c
  179. ;TP.l=MTablePtr
  180. ;For SourceColour=0 To 255
  181. ;  For DestColour=0 To 255
  182. ;    Offset.l=(SourceColour LSL 8)+DestColour
  183. ;R0=(R(SourceColour)+R(DestColour)) LSR 1
  184. ;G0=(G(SourceColour)+G(DestColour)) LSR 1
  185. ;B0=(B(SourceColour)+B(DestColour)) LSR 1
  186. ;;R0=Min((R(SourceColour)+R(DestColour)),255)
  187. ;;G0=Min((G(SourceColour)+G(DestColour)),255)
  188. ;;B0=Min((B(SourceColour)+B(DestColour)),255)
  189. ;;R0=R(DestColour)*0.8
  190. ;;G0=G(DestColour)*0.8
  191. ;;B0=B(DestColour)*0.8
  192. ;    Best=0
  193. ;    BestTotal.l=$0FFFFFFF
  194. ;    For TestColour=0 To 255
  195. ;      R1=R(TestColour)
  196. ;      G1=G(TestColour)
  197. ;      B1=B(TestColour)
  198. ;      Total.l=((R0-R1)*(R0-R1))+((G0-G1)*(G0-G1))+((B0-B1)*(B0-B1))
  199. ;      If Abs(Total)<BestTotal
  200. ;        Best=TestColour
  201. ;        BestTotal=Abs(Total)
  202. ;      EndIf
  203. ;    Next TestColour
  204. ;    Poke.b TP+Offset,Best
  205. ;  Next DestColour
  206. ;Next SourceColour
  207. ;;*** runtime ***
  208. ;;Save off the generated table here
  209. ;If WriteFile(0,"Orion.Table")=False Then Goto Finish
  210. ;WriteMem 0,MTablePtr,256*256
  211. ;CloseFile 0
  212.  
  213. .Loop
  214. buf.b=0
  215. its.l=0
  216. cnt.b=0
  217. ResetTimer
  218. While Joyb(0)=0 AND Joyb(1)=0
  219.  
  220.   xpos=SMouseX
  221.   ypos=SMouseY
  222.   MHandle 0,xpos,ypos
  223.   MReMapUsingShape MTablePtr,0,0
  224.   MQDummy xpos,ypos,#ObjSize,#ObjSize
  225.  
  226.   ;Display
  227.   If IsAGA
  228.     Mc2p MBitmapPtr(0),PlanarBuf(buf)
  229.     ShowBitMap buf
  230.     If PrefDisplayBuffering>1
  231.       buf+1
  232.       If buf=PrefDisplayBuffering Then buf=0
  233.     EndIf
  234.   Else
  235.     MUseBitmap 4
  236.     If PrefDisplayBuffering>1
  237.       MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,PrefDisplayHeight+(cnt*PrefDisplayHeight),0
  238.       *RP0._RastPort=RastPort(0)
  239.       *RP1._RastPort=RastPort(Min(PrefDisplayBuffering-1,1+cnt))
  240.       ClipBlit_ *RP1,0,0,*RP0,0,0,PrefDisplayWidth,PrefDisplayHeight,$C0
  241.       If PrefDisplayBuffering=3 Then cnt=1-cnt ; Toggle output buffer
  242.     Else
  243.       MBlockScroll 0,0,PrefDisplayWidth,PrefDisplayHeight,0,0,0
  244.     EndIf
  245.     MUseBitmap 0
  246.   EndIf
  247.  
  248.   MUnQueue 0,1
  249.  
  250.   its+1
  251. Wend
  252.  
  253. ;Report
  254. t=Timer
  255. t=Max(t,1)
  256. its=Max(its,1)
  257. a.q=50.0/(t/its)
  258. ;SaveBitmap 0,"Ram:Snap.IFF",0
  259. WBenchToFront_
  260. FindScreen 1
  261. Window 2,16,16,300,40,0,"Test results",1,0
  262. WindowOutput 2
  263. NPrint a," frames per second"
  264. NPrint " "
  265. NPrint "Press mouse/joy button..."
  266. Repeat
  267. Until Joyb(0)<>0 OR Joyb(1)<>0
  268.  
  269. Finish:
  270. End
  271.  
  272.